<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>分公司采购计划单列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../res/layui-v2.5.6/css/layui.css" media="all">
    <script type="text/javascript" src="../../../res/js/jquery-3.4.1.min.js"></script>
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">

    <div class="demoTable">
        搜索关键字：
        <div class="layui-inline">
            <input class="layui-input" name="operator" id="operator" autocomplete="off" placeholder="请输入采购人">
        </div>
        时间：
        <div class="layui-input-inline">
            <input type="text" name="startTime" id="startTime" autocomplete="off" class="layui-input" placeholder="yyyy-MM-dd">
        </div>
        --
        <div class="layui-input-inline">
            <input type="text" name="endTime" id="endTime" autocomplete="off" class="layui-input" placeholder="yyyy-MM-dd">
        </div>
        <button class="layui-btn" data-type="reload" id="sousuo" onclick="seach(this)">搜索</button>
    </div>

</script>

<script type="text/html" id="barDemo2">
    <a class="layui-btn layui-btn-xs" lay-event="ImmPurchaseDeatis">查询订单详情</a>
    <a class="layui-btn layui-btn-xs" lay-event="HqReview">查询审核详情</a>
</script>

<script type="text/html" id="barDemo">
    {{# if(d.isva == 66 ){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="tuihuo">查询物流详情</a>
    {{# }else{ }}
    <button class="layui-btn layui-btn-xs layui-btn-disabled" disabled="" lay-event="tuihuo">查询物流详情</button>
    {{# } }}

</script>
<script type="text/html" id="salesReturn">
    {{# if(d.isva == 66){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="one">入库</a>
    {{# }else{ }}
    <button class="layui-btn layui-btn-xs layui-btn-disabled" disabled="" lay-event="one">入库</button>
    {{# } }}
</script>

<script type="text/html" id="img">
    <img src="/img/upload/{{d.proImg}}" alt="图片" width="50" height="50" onclick="showBig(this)"/>
</script>
<script type="text/javascript" src="../../../res/layui-v2.5.6/layui.js"></script>
<script>
    var openIndex = null;
    var table = null;
    var laydate = null;
    layui.use(['table', 'laydate'], function () {
        table = layui.table;
        laydate = layui.laydate;
        table.render({
            method:"POST",
            elem: '#test'
            , url: '/immPurchase/queryAll3'
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: false
            , title: '分公司采购计划单数据表'
            , cols: [[
                 {field: 'purchaseId', title: '采购单ID', fixed: 'left'},
                 {field: 'immName', title: '分公司名称',align:"center"}
                , {field: 'purchaseCount', title: '采购总数量',align:"center"}
                , {field: 'purchaseMoney', title: '采购总金额',align:"center"}
                , {field: 'operator', title: '采购人', align:"center"}
                , {field: 'purchaseTime', title: '采购时间', align:"center"}
                , {field: 'isva', title: '审核状态', width: 150,align:"center",templet:function(d){
                        if(d.isva == '10'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">未申请</p>';
                        } else if(d.isva == '20'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">已申请</p>';
                        }else if(d.isva == '30'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">分公司采购经理通过</p>';
                        }else if(d.isva == '31'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">分公司采购经理不通过</p>';
                        }else if(d.isva == '40'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">分公司总经理通过</p>';
                        }else if(d.isva == '41'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">分公司总经理不通过</p>';
                        }else if(d.isva == '50'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">总公司销售经理通过</p>';
                        }else if(d.isva == '51'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">总公司销售经理不通过</p>';
                        }else if(d.isva == '60'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">总公司总经理通过</p>';
                        }else if(d.isva == '61'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">总公司总经理不通过</p>';
                        }else if(d.isva == '80'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">已提交退货申请</p>';
                        }else if(d.isva == '81'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">总公司通过</p>';
                        }else if(d.isva == '66'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">退货中</p>';
                        }else if(d.isva == '67'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">退货失败</p>';
                        }else if(d.isva == '65'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">总公司审核中</p>';
                        }else if(d.isva == '1'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">等买家输入运单号</p>';
                        }
                    }}
                , {field: 'remark', title: '备注', align:"center"}
                , {fixed: 'right', title: '查询信息', width: 210, toolbar: '#barDemo2',align:"center"}
                , {fixed: 'right', title: '物流查询', width: 180, toolbar: '#barDemo', align:"center"}
                , {fixed: 'right', title: '是否入库', width: 180, toolbar: '#salesReturn', align:"center"}
            ]]
            , page: true
            , id: 'test'
            ,where: {  //查询采购单状态为 提交退货申请(68)
                isva: 66  //过滤已经经过的流程
            }
        });



        //日期时间选择器
        laydate.render({
            elem: '#startTime'
            ,trigger: 'click'
        });

        laydate.render({
            elem: '#endTime'
            ,trigger: 'click'
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'Increasedata':
                    openIndex = layer.open({
                        type: 2,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['85%', '85%'], //宽高
                        title: '增加',
                        maxmin: true, //开启最大化最小化按钮
                        content: 'immPurchase-edit_add.html',
                    });
                    break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    var purchaseId = data.purchaseId;
                    console.info(purchaseId);
                    var url = "/immPurchase/delete/"+purchaseId;
                    $.ajax({
                        url: url,
                        processData: false,
                        contentType: false,
                        dataType: 'json',
                        type: 'DELETE',
                        success: function (obj) {
                            if (obj.status == 20) {
                                layer.msg(obj.message);
                                table.reload('test');
                            }else{
                                layer.msg(obj.message);
                            }
                        },
                        error: function () {

                        }
                    });
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                var id = data.purchaseId;
                openIndex = layer.open({
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['85%', '85%'], //宽高
                    title: '编辑',
                    maxmin: true, //开启最大化最小化按钮
                    content: 'immPurchase-edit_add.html?id=' + id,
                });
            }else if (obj.event === 'tuihuo') {
                var id = data.purchaseId;
                openIndex = layer.open({
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['100%', '108%'], //宽高
                    title: '退货',
                    maxmin: true, //开启最大化最小化按钮
                    content: '../mapRetrun.html?id='+id,
                    success:function (layero,index) {
                        var body = layer.getChildFrame('body',index); //确定两个页面之间的父子关系
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //子页面对象
                        body.find("#pcId").val(id);
                    }
                });
            }else if (obj.event === 'one') {
                var id1 = data.purchaseId;
                var url = "/orderReturnApply/financeDeposit?id="+id1;
                $.ajax({
                    url: url,
                    processData: false,
                    contentType: false,
                    dataType: 'json',
                    type: 'GET',
                    success: function (obj) {
                        if (obj.status == 20) {
                            layer.msg(obj.message);
                            table.reload('test');
                        }else{
                            layer.msg(obj.message);
                        }
                    },
                    error: function () {

                    }
                });
            }else if (obj.event === 'ruku') {
                var id = data.purchaseId;
                openIndex = layer.open({
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['75%', '85%'], //宽高
                    title: '质检入库',
                    maxmin: true, //开启最大化最小化按钮
                    content: 'ruku.html?id=' + id,
                });
            }else if(obj.event === "ImmPurchaseDeatis"){
                pcId = data.purchaseId;
                var id = data.purchaseId;
                openIndex = layer.open({
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['75%', '75%'], //宽高
                    title: '采购明细',
                    maxmin: true, //开启最大化最小化按钮
                    content: 'immPurchaseDeatis.html?id=' + id,
                });
            }else if(obj.event === "HqReview"){
                var id = data.purchaseId;
                openIndex = layer.open({
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['75%', '75%'], //宽高
                    title: '审核记录',
                    maxmin: true, //开启最大化最小化按钮
                    content: 'auditRecord.html?id=' + id,
                });
            }else if(obj.event === "ApplyImmediately"){
                var id = data.purchaseId;
                console.info(id);
                $.ajax({
                    url: '/immPurchase/updateReviewState',
                    data: {purchaseId:id},
                    dataType: 'json',
                    type: 'POST',
                    success: function (obj) {
                        if (obj.status == 20) {
                            layer.msg("申请成功");
                            table.reload('test');
                        }else{
                            layer.msg("操作失败");
                        }
                    },
                    error: function () {

                    }
                });
            }
        });
    });


    //搜索
    function seach() {
        var operator = $("#operator").val();
        var startTime = $("#startTime").val();
        var endTime = $("#endTime").val();
        var reviewState = $("#reviewState").val();
        table.reload('test', {
            where: {
                operator: operator,
                startTime: startTime,
                endTime: endTime,
                reviewState: reviewState
            },
            page: {
                curr: 1//从第一页开始查询
            }
        });

        //日期时间选择器
        laydate.render({
            elem: '#startTime'
            ,trigger: 'click'
        });

        laydate.render({
            elem: '#endTime'
            ,trigger: 'click'
        });
    }


    function close(obj) {
        layer.close(openIndex);
    }

    /**
     * 关闭弹出层
     */
    function closeOpen(msg) {
        layer.close(openIndex);
        layer.msg(msg, {time: 1000}, function () {
            table.reload("test");//刷新表格
        })
    }
</script>
</body>
</html>